package com.invengo.module_check.ui.fragment.find_error.item;

import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.invengo.library_db.entity.module_check.BookBean;
import com.invengo.module_check.ui.fragment.find_error.FindErrorViewModel;
import com.invengo.module_check.ui.fragment.guide_listing.ListingGuideViewModel;

import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;

public class FindErrorItmeViewModel extends ItemViewModel<FindErrorViewModel> {

    public SingleLiveEvent<BookBean> book = new SingleLiveEvent<>();
    public SingleLiveEvent<String> tid = new SingleLiveEvent<>();

    public FindErrorItmeViewModel(@NonNull FindErrorViewModel viewModel, BookBean bean) {
        super(viewModel);
        if (TextUtils.isEmpty(bean.getBookName())) {
            bean.setBookName("异常图书");
            bean.setShelfName("未知");
        }
        if (TextUtils.isEmpty(bean.getBarCode())) {
            bean.setBarCode("未知");
        }
        this.book.postValue(bean);
        tid.postValue(bean.getTid());
    }

    public BindingCommand removeItem = new BindingCommand(() -> {
        viewModel.onItemRemove(this);
    });

    public int getPosition() {
        return viewModel.getPosition(this) + 1;
    }

}
